package com.longge;

/**
 * @program: my-code
 * @description:
 * @author: longge
 * @create: 2021-03-11 00:41
 */
public class IsValidBST {
    public boolean isValidBST(TreeNode root) {
        return dfs(root,null,null);
    }

    private boolean dfs(TreeNode root, TreeNode min, TreeNode max) {
        if (root==null) return true;
        if ((min!=null&&root.val<=min.val)||(max!=null&&root.val>=max.val)){
            return false;
        }
       return dfs(root.left,min,root)&&dfs(root.right,root,max);

    }


}
